package com.zywl.api;

import com.github.pagehelper.util.StringUtil;
import com.zywl.core.beans.Agreement;
import com.zywl.service.AgreementService;
import com.zywl.utils.models.JsonResult;
import com.zywl.web.controller.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/agreement/")
public class AgreementApi extends BaseController {
    @Autowired
    private AgreementService agreementService;

    /**
     * 获取协议详情
     * @return
     */
    @ResponseBody
    @RequestMapping("detail")
    public JsonResult detail(String assId,String index){
        JsonResult jr = new JsonResult();
        try {
            Agreement agreement =  agreementService.getById(Long.valueOf(assId));
            if("1".equals(index)){
                jr.success("操作成功",agreement.getAgmMemberExplain());
            }else if("2".equals(index)){
                jr.success("操作成功",agreement.getAgmFeeExplain());
            }else if("3".equals(index)){
                jr.success("操作成功",agreement.getAgmUserAgreement());
            }else if("4".equals(index)){
                jr.success("操作成功",agreement.getAgmPrivacyAgreement());
            }else{
                jr.success("操作成功",agreement);
            }
        }catch (Exception e){
            logger.error("获取详情失败",e);
            jr.error("获取详情失败");
        }
        return jr;
    }


}
